home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: Oct 1999
- //
- //
- //<doc>
- //<name validateShelfName>
- //<owner "Alias|Wavefront Unsupported">
- //
- //<synopsis>
- // validateShelfName (string $newName)
- //
- //<returns>
- // int : 1 if the name is valid, 0 otherwise
- //
- //<description>
- // This script is called to make verify that a potential name
- // for a shelf tab is valid.
- //
- //<flags>
- // string $newName Potential shelf name to check.
- //
- //<examples>
- // validateShelfName "123isNotValid";
- //
- //</doc>
-
- global proc int validateShelfName (string $newName)
- {
- int $isOkay = true;
-
- string $regex = "[^0-9a-zA-Z_]";
- string $firstCharRegex = "[0-9]";
- string $match = match( $regex, $newName );
-
- string $fileName = (`internalVar -userShelfDir` + "shelf_" + $newName + ".mel");
-
- //
- // test for zero length
- //
- if (size($newName) == 0) {
- confirmDialog -title "Alert"
- -button "OK" -defaultButton "OK"
- -message " Shelf name must be one or more characters long. Please enter a name. ";
- $isOkay = false;
- //
- // test for bad characters
- //
- } else if ($match != "") {
- confirmDialog -title "Alert"
- -button "OK" -defaultButton "OK"
- -message (" Shelf name contains illegal characters. Please select another name. \n"+
- "Valid names can contain only letters, numbers and underscores.");
- $isOkay = false;
- //
- // test for bad first character
- //
- } else if ("" != match($firstCharRegex, `substring $newName 1 1`)) {
- confirmDialog -title "Alert"
- -button "OK" -defaultButton "OK"
- -message " Shelf name cannot begin with a numeric character. Please select another name. ";
- $isOkay = false;
- //
- // test for existing saved shelves
- //
- } else if (`file -q -exists $fileName`) {
- confirmDialog -title "Alert"
- -button "OK" -defaultButton "OK"
- -message " Shelf name is not unique. Please select another name. ";
- $isOkay = false;
- } else {
- //
- // test for existing shelves in optionVars
- //
- string $shelfName;
- $nShelves = `optionVar -q numShelves`;
- for ($i = 1; $i <= $nShelves; $i++) {
- $varName = ("shelfName" + $i);
- $shelfName = `optionVar -q $varName`;
- if ($shelfName == $newName) {
- $isOkay = false;
- break;
- }
- }
-
- if (!$isOkay) {
- confirmDialog -title "Alert"
- -button "OK" -defaultButton "OK"
- -message " Shelf name is not unique. Please select another name. ";
- }
- }
-
- return $isOkay;
- }
-